/*
 * <one line to give the program's name and a brief idea of what it does.>
 * Copyright (C) 2019
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef SHIPPART_H
#define SHIPPART_H

#include "commondata.hpp"

/**
 * \class ShipPart
 * Class for describe ship parts.
 * Weapon, hull, reactor and wings
 */
class ShipPart {
public:
	ShipPart(const upgradeType type, uint16_t level);
	ShipPart(const ShipPart & other) = delete;
	~ShipPart() {};

	/**
	 * set part level
	 * \param[in] level part level
	 */
	void setLevel(const uint16_t level) {
		m_Level = level;
		updateValue();
	}

	/**
	 * get part level
	 * \return current part level
	 */
	uint16_t getLevel() const {
		return m_Level;
	}

	/**
	 * Each part increase ship params
	 * \return current part value
	 */
	double getValue() const {
		return m_Value;
	}

	/**
	 * How many resources needed to upgrade part to current level from previous
	 * \param[in] level part level
	 * \return Amount of resources needed to upgrade
	 */
	static resource upgradePrice(uint16_t level);

	/**
	 * How many resources needed to upgrade part from A to B levels
	 * \param[in] a begin level
	 * \param[in] b end level
	 * \return Amount of resources needed to upgrade
	 */
	static resource upgradePriceDiff(uint16_t begin, uint16_t end);

	/**
	 * How many times part can be upgraded from choosen level with current resources
	 * \param[in] level begin level
	 * \param[in] res current resources
	 * \return max upgrade level for part
	 * \todo still need this function? TODO
	 */
	static uint16_t upgradeMaxLevel(const uint16_t level, const resource & res);

private:
	uint16_t m_Level = 0;
	double m_Value = 0;
	const upgradeType m_Type;

	/**
	 * Recalculate part value
	 */
	void updateValue();
};

#endif // SHIPPART_H
